'use strict';

/* Controllers */
// 投资排行活动管理
app.controller('rankingmanage', ['$scope', '$rootScope', 'commonFactory', 'toaster', '$modal', '$timeout', function ($scope, $rootScope, commonFactory, toaster, $modal, $timeout) {
    $scope.searchrankingmanage = {
        Index: 1,
        Size: 16
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.searchrankingmanage.Index >= $scope.page) {//判断最大页码
                $scope.searchrankingmanage.Index = $scope.page;
                return false;
            }
            $scope.searchrankingmanage.Index++
            requestRanking();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.searchrankingmanage.Index <= 1) {//判断最小页码
            $scope.searchrankingmanage.Index = 1;
            return false;
        }
        $scope.searchrankingmanage.Index--;
        requestRanking()
    }
    // 删除缓存
    $scope.deleteCache = function () {
        commonFactory.ajax("/api/Ranking/RemoveCache", {}, function (result) {
            if (result.Code == 1) {
                toaster.pop('success', '', '删除缓存成功');
                requestRanking();
            } else {
                toaster.pop('error', '', '删除缓存失败');
            }

        }, function () {

        }, "post");
    }
    // 添加
    $scope.addRanking = function () {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout) {
                $scope.rankingData = {
                    Serial: '',
                    StartTime: '',
                    EndTime: ''
                }
                $scope.isadd = true;
                $scope.RankingShow = true;
                $scope.add = function () {
                    if (!$scope.rankingData.Serial) {
                        toaster.pop('warning', '', '请填写活动期数');
                        return
                    }
                    if (!$scope.rankingData.StartTime) {
                        toaster.pop('warning', '', '请选择活动开始日期');
                        return
                    }
                    if (!$scope.rankingData.EndTime) {
                        toaster.pop('warning', '', '请选择活动结束日期');
                        return
                    }
                    commonFactory.ajax(commonFactory.timeurl+"/api/bank/gettime", {}, function (result) {
                        var serverTime = new Date(result.data.replace(/-/g,"\/"));             
                        var newserverTime = new Date(new Date(serverTime.setHours(0)).setMinutes(0)).setSeconds(0)
                        if($scope.rankingData.StartTime.getTime()<newserverTime){
                            toaster.pop('warning', '', '开始日期必须大于等于当前日期');
                            return
                        }
                        if($scope.rankingData.EndTime.getTime()<=$scope.rankingData.StartTime.getTime()){
                            toaster.pop('warning', '', '结束日期必须大于开始日期');
                            return
                        }
                        if ($scope.isadd) {
                            $scope.isadd = false
                            $scope.rankingData.StartTime = commonFactory.DateFormat($scope.rankingData.StartTime);
                            $scope.rankingData.EndTime = commonFactory.DateFormat($scope.rankingData.EndTime);
                            commonFactory.ajax("/api/Ranking/Add", $scope.rankingData, function (result) {
                                if (result.Code == 1) {
                                    $scope.isadd = true;
                                    toaster.pop('success', '', '添加活动成功');
                                    $modalInstance.close('cancel');
                                } else {
                                    toaster.pop('warning', '', '添加活动失败');
                                    $modalInstance.close('cancel');
                                }
                            }, function () {
                                toaster.pop('error', '', '后台错误');
                            }, "post");
                        }
                    }, function () { }, 'post')
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: '',
            backdrop: true
        });
        modalInstance.result.then(function (selectedItem) {
            requestRanking()
        }, function () {

        });
    }
    // 查询
    $scope.queryRanking = function () {
        $scope.graybtn = true;
        $scope.searchrankingmanage.Index = 1;
        requestRanking();
    }
    var requestRanking = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Ranking/QueryList", $scope.searchrankingmanage, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Code == 1) {
                $scope.GetRankingList = result.Data.List;
                $scope.QueryListTotal = result.Data.Total;

                $scope.page = Math.ceil(result.Data.Total / $scope.searchrankingmanage.Size);
            } else {
                commonFactory.loading(false)
                $scope.graybtn = false;
                toaster.pop('error', '', '失败');
            }
        }, function () {

        }, "post");
    }
    requestRanking()

}]);
// 投资排行榜获奖记录
app.controller('ranking', ['$scope', '$rootScope', 'commonFactory', 'toaster', '$modal', '$timeout', function ($scope, $rootScope, commonFactory, toaster, $modal, $timeout) {
    $scope.searchRankingDetail = {
        Index: 1,
        Size: 15,
        UserName:'',
        Mobile:'',
        StartTime:'',
        EndTime:''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.searchRankingDetail.Index >= $scope.page) {//判断最大页码
                $scope.searchRankingDetail.Index = $scope.page;
                return false;
            }
            $scope.searchRankingDetail.Index++
            reqRankingDetail();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.searchRankingDetail.Index <= 1) {//判断最小页码
            $scope.searchRankingDetail.Index = 1;
            return false;
        }
        $scope.searchRankingDetail.Index--;
        reqRankingDetail()
    }
    $scope.inpvalue = {
        num: '1'
    }
    // 查询
    $scope.queryRankingDetail = function () {
        $scope.graybtn = true;
        if (!$scope.searchRankingDetail.StartTime) {
            $scope.searchRankingDetail.StartTime=""
        }else{
            $scope.searchRankingDetail.StartTime = commonFactory.DateFormat($scope.searchRankingDetail.StartTime);
        }
        if (!$scope.searchRankingDetail.EndTime) {
            $scope.searchRankingDetail.EndTime=""
        }else{
            $scope.searchRankingDetail.EndTime = commonFactory.DateFormat($scope.searchRankingDetail.EndTime);
        }
        $scope.searchRankingDetail.Index = 1;
        reqRankingDetail();
    }
    var reqRankingDetail = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/RankingDetail/QueryList", $scope.searchRankingDetail, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Data != null) {
                $scope.GetRankingDetailList = result.Data.List;
                $scope.QueryListTotal = result.Data.Total;
                $scope.page = Math.ceil(result.Data.Total / $scope.searchRankingDetail.Size);
            } else {
                commonFactory.loading(false)
                $scope.graybtn = false;
                toaster.pop('error', '', '失败');
            }
        }, function () {

        }, "post");
    }
    reqRankingDetail()

}]);
// 发放加息券
app.controller('operate', ['$scope', 'commonFactory', 'toaster', '$timeout', function ($scope, commonFactory, toaster, $timeout) {
    $scope.allinp = {
        title: '发放加息券',
        rate: '',
        endTime: '',
        startTime:'',
        mobile: ''
    }
    var checkinp = function () {
        if (!$scope.allinp.rate || $scope.allinp.rate <= 0 || $scope.allinp.rate >= 10) {
            toaster.pop('warning', '', '请填写正确的加息利率1~9');
            return
        }
        var select = document.querySelector('#myinp').value;
        var select1 = document.querySelector('#myinp1').value
        if (!select||!select1) {
            toaster.pop('warning', '', '请填写时间');
            return
        }
        var startTime = new Date($scope.allinp.startTime).getTime();  
        var endTime =new Date($scope.allinp.endTime).getTime(); 
        if(startTime>endTime){
            toaster.pop('warning', '', '结束日期必须大于等于开始日期');
            return
        }
        if (!$scope.allinp.mobile) {
            toaster.pop('warning', '', '请填写手机号');
            return
        }
        return true
    }
    $scope.show = true;
    $scope.butplus = function () {
        if($scope.allinp.endTime){
            $scope.allinp.endTime = commonFactory.DateFormat($scope.allinp.endTime);
        }else{
            $scope.allinp.endTime = '';
        }
        if($scope.allinp.startTime){
            $scope.allinp.startTime = commonFactory.DateFormat($scope.allinp.startTime);
        }else{
            $scope.allinp.startTime = '';
        }
        
        
        if (checkinp() && $scope.show) {
            $scope.show = false;
            commonFactory.loading(true)
            commonFactory.ajax("/api/PlusInterest/SavePlus", $scope.allinp, function (result) {
                commonFactory.loading(false)
                if (result.Code == 1) {
                    $timeout(function() {
                        $scope.show = true;
                    }, 500);
                    toaster.pop('success', '', result.ResposeData);
                } else {
                    $scope.show = true;
                    if(result.ResposeData){
                        toaster.pop('warning', '', result.ResposeData);
                    }else{
                        toaster.pop('warning', '', '未发放成功');
                    }
                }
            }, function () {
                commonFactory.loading(false)
                toaster.pop('error', '', '后台错误');
            }, "post");
        }
    }
}]);

// 广告管理
app.controller('ad', ['$scope', '$rootScope', 'commonFactory', 'toaster', '$modal', '$timeout', function ($scope, $rootScope, commonFactory, toaster, $modal, $timeout) {
    $scope.AdData = {
        Index: 1,
        Size: 5,
        AdTypeId: '',
        AdTitle: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.AdData.Index >= $scope.page) {//判断最大页码
                $scope.AdData.Index = $scope.page;
                return false;
            }
            $scope.AdData.Index++
            requestAdList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.AdData.Index <= 1) {//判断最小页码
            $scope.AdData.Index = 1;
            return false;
        }
        $scope.AdData.Index--;
        requestAdList()
    }
    // 查询
    $scope.queryAd = function () {
        $scope.graybtn = true;
        $scope.AdData.Index = 1;
        requestAdList();
    }
    // 排序
    $scope.sortAd = function () {
        // requestNoticeList();
    }
    // 添加
    $scope.addAd = function () {
        localStorage.setItem("Ad", '');
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout) {
                $scope.imgurlad = false;
                $scope.Aditems = {
                    AdTitle: '',
                    AdUrl: '',
                    AdSort: 0,
                    AdTypeId: '1',
                    StartTime: '',
                    EndTime: '',
                    AdImage: ''
                }
                $scope.isadd = true;
                $scope.istrue = false;
                $scope.addAds = function () {
                    if (checkinp() && $scope.isadd) {
                        $scope.isadd = false
                        localStorage.setItem("Ad", '');
                        $scope.Aditems.StartTime = commonFactory.DateFormat($scope.Aditems.StartTime);
                        $scope.Aditems.EndTime = commonFactory.DateFormat($scope.Aditems.EndTime);
                        commonFactory.ajax("/api/Banner/AddBanner", $scope.Aditems, function (result) {
                            if (result.Code == 1) {
                                $scope.isadd = true;
                                toaster.pop('success', '', '添加广告成功');
                                $modalInstance.close('cancel');
                            } else {
                                toaster.pop('warning', '', '添加广告失败');
                                $modalInstance.close('cancel');
                            }
                        }, function () {
                            toaster.pop('error', '', '后台错误');
                        }, "post");
                    }
                }
                var checkinp = function () {
                    if (!$scope.Aditems.AdTitle) {
                        toaster.pop('warning', '', '请填写广告标题');
                        return
                    }
                    if ($scope.Aditems.AdSort === "") {
                        toaster.pop('warning', '', '请填写广告排序');
                        return
                    }
                    if (!$scope.Aditems.AdTypeId) {
                        toaster.pop('warning', '', '请填写广告类别 ');
                        return
                    }
                    if (!$scope.Aditems.StartTime) {
                        toaster.pop('warning', '', '请填写开始时间');
                        return
                    }
                    if (!$scope.Aditems.EndTime) {
                        toaster.pop('warning', '', '请填写结束时间');
                        return
                    }
                    if (!$scope.Aditems.AdImage) {
                        toaster.pop('warning', '', '请上传广告图片 ');
                        return
                    } else if ($scope.Aditems.AdImage[0].indexOf(".jpg") == -1 && $scope.Aditems.AdImage[0].indexOf(".png") == -1 && $scope.Aditems.AdImage[0].indexOf(".JPG") == -1 && $scope.Aditems.AdImage[0].indexOf(".PNG") == -1) {
                        toaster.pop('warning', '', '上传图片中包含非jpg、png格式，请重新选择上传');
                        return;
                    }
                    return true
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'lg',
            backdrop: true
        });
        modalInstance.result.then(function (selectedItem) {
            requestAdList()
        }, function () {

        });
    }
    // 删除缓存
    $scope.deleteCache = function () {
        commonFactory.ajax("/api/banner/deletecache", {}, function (result) {
            if (result.Code == 1) {
                toaster.pop('success', '', '删除缓存成功');
                requestAdList();
            } else {
                toaster.pop('error', '', '删除缓存失败');
            }

        }, function () {

        }, "post");
    }
    // 删除
    $scope.deleteAd = function (obj) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'items', 'toaster', 'commonFactory', function ($scope, $modalInstance, items, toaster, commonFactory) {
                $scope.items = items;
                $scope.ok = function () {
                    //删除
                    commonFactory.ajax("/api/banner/remove/" + $scope.items, {}, function (result) {
                        if (result.Code == 1) {
                            toaster.pop('success', '', '删除广告成功');
                            $modalInstance.close();
                        } else {
                            toaster.pop('error', '', '删除广告失败');
                            $modalInstance.close();
                        }

                    }, function () {

                    }, "post");
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false,
            resolve: {
                items: function () {
                    return obj;
                }
            }
        });
        modalInstance.result.then(function (selectedItem) {
            $timeout(function () {
                requestAdList();
            }, 100);
        }, function () {

        });
    }
    // 编辑
    $scope.editAd = function (obj) {
        localStorage.setItem("Ad", JSON.stringify(obj));
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', '$interval', function ($scope, $modalInstance, toaster, commonFactory, $timeout, $interval) {
                $scope.Aditems = {
                    AdTitle: '',
                    AdUrl: '',
                    AdSort: 0,
                    AdTypeId: '1',
                    StartTime: '',
                    EndTime: '',
                    AdImage: ''
                }
                var interval = $interval(function () {
                    if ($scope.Aditems.AdImage) {
                        $interval.cancel(interval);
                        $scope.imgurlad = $scope.Aditems.AdImage[0]
                    }
                }, 100)
                $scope.isadd = true;
                var adlist = localStorage.getItem("Ad")
                $scope.adimg = JSON.parse(adlist).AdImage;
                if (adlist) {
                    $scope.istrue = true;
                    adlist = JSON.parse(adlist);
                    $scope.Id = adlist.Id;
                    $scope.Aditems.AdTitle = adlist.AdTitle;
                    $scope.Aditems.AdUrl = adlist.AdUrl;
                    $scope.Aditems.AdSort = adlist.AdSort;
                    $scope.Aditems.AdTypeId = adlist.AdTypeId;
                    $scope.Aditems.StartTime = adlist.StartTime;
                    $scope.Aditems.EndTime = adlist.EndTime;
                }
                $scope.editAds = function () {
                    if (checkinp() && $scope.isadd) {
                        $scope.Aditems1 = $scope.Aditems;
                        $scope.Aditems1.Id = $scope.Id;
                        $scope.isadd = false
                        $scope.Aditems.StartTime = commonFactory.DateFormat($scope.Aditems.StartTime);
                        $scope.Aditems.EndTime = commonFactory.DateFormat($scope.Aditems.EndTime);
                        commonFactory.ajax("/api/Banner/AddBanner", $scope.Aditems1, function (result) {
                            if (result.Code == 1) {
                                $scope.isadd = true;
                                toaster.pop('success', '', '编辑广告成功');
                                $modalInstance.close('cancel');
                            } else {
                                toaster.pop('warning', '', '编辑广告失败');
                                $modalInstance.close('cancel');
                            }
                        }, function () {
                            toaster.pop('error', '', '后台错误');
                        }, "post");
                    }
                }
                var checkinp = function () {
                    if (!$scope.Aditems.AdTitle) {
                        toaster.pop('warning', '', '请填写广告标题');
                        return
                    }
                    if ($scope.Aditems.AdSort === "") {
                        toaster.pop('warning', '', '请填写广告排序');
                        return
                    }
                    if (!$scope.Aditems.AdTypeId) {
                        toaster.pop('warning', '', '请填写广告类别 ');
                        return
                    }
                    if (!$scope.Aditems.StartTime) {
                        toaster.pop('warning', '', '请填写开始时间');
                        return
                    }
                    if (!$scope.Aditems.EndTime) {
                        toaster.pop('warning', '', '请填写结束时间');
                        return
                    }
                    if (!$scope.Aditems.AdImage) {
                        $scope.Aditems.AdImage = adlist.AdImage;
                        return true
                    } else if ($scope.Aditems.AdImage[0].indexOf(".jpg") == -1 && $scope.Aditems.AdImage[0].indexOf(".png") == -1 && $scope.Aditems.AdImage[0].indexOf(".JPG") == -1 && $scope.Aditems.AdImage[0].indexOf(".PNG") == -1) {
                        toaster.pop('warning', '', '上传图片中包含非jpg、png格式，请重新选择上传');
                        return;
                    }
                    return true
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: '',
            backdrop: false
        });
        modalInstance.result.then(function (selectedItem) {
            requestAdList()
        }, function () {

        });
    }
    var requestAdList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Banner/Query", $scope.AdData, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Count >= 0) {
                $scope.AdList = result.Data;
                $scope.QueryListTotal = result.Count;
                $scope.page = Math.ceil(result.Count / $scope.AdData.Size);
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requestAdList()
}]);

// 公告管理
app.controller('notices', ['$scope', 'commonFactory', 'toaster', '$modal', function ($scope, commonFactory, toaster, $modal) {
    $scope.QueryNotice = {
        PageIndex: 1,
        PageSize: 5,
        Title: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.QueryNotice.PageIndex >= $scope.page) {//判断最大页码
                $scope.QueryNotice.PageIndex = $scope.page;
                return false;
            }
            $scope.QueryNotice.PageIndex++
            requestNoticeList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.QueryNotice.PageIndex <= 1) {//判断最小页码
            $scope.QueryNotice.PageIndex = 1;
            return false;
        }
        $scope.QueryNotice.PageIndex--;
        requestNoticeList()
    }
    $scope.QueryNotices = function () {
        $scope.graybtn = true;
        $scope.QueryNotice.PageIndex = 1;
        requestNoticeList();
    }
    // 添加公告
    $scope.addNotices = function (nid) {
        localStorage.setItem("NoticesId", nid)
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout) {
                $scope.addNotice = {
                    Title: '',
                    Content: "",
                    UserName: "",
                    IsTop: "false"
                }
                var checkinp = function () {
                    if (!$scope.addNotice.Title) {
                        toaster.pop('warning', '', '请填写标题 ');
                        return
                    }
                    if (!$scope.addNotice.UserName) {
                        toaster.pop('warning', '', '请填写客服信息');
                        return
                    }
                    if (!$scope.addNotice.Content) {
                        toaster.pop('warning', '', '请填写内容');
                        return
                    }
                    // $scope.addNotice.Content = encodeURIComponent($scope.addNotice.Content);
                    return true
                }
                
                $scope.addgg = true;
                $scope.addNotices = function () {
                    if (checkinp() && $scope.addgg) {
                        $scope.addgg = false
                        commonFactory.loading(true)
                        $scope.addNotice.Content = encodeURIComponent($scope.addNotice.Content);
                        commonFactory.ajax("/api/Notices/AddNotices", $scope.addNotice, function (result) {
                            commonFactory.loading(false)
                            if (result.Code == 1) {
                                $scope.addgg = true;
                                toaster.pop('success', '', '添加公告成功');
                                $modalInstance.close();
                            } else {
                                toaster.pop('warning', '', '添加公告失败');
                            }
                        }, function () {
                            commonFactory.loading(false)
                            toaster.pop('error', '', '后台错误');
                        }, "post");
                    }
                }
                $scope.cancel = function () {
                    $modalInstance.close();
                };
            }],
            size: '',
            backdrop: false
        });
        modalInstance.result.then(function (selectedItem) {
            requestNoticeList()
        }, function () {

        });
    }
    // 编辑公告
    $scope.editNotices = function (nid) {
        localStorage.setItem("NoticesId", nid)
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout) {
                $scope.editNotice = {
                    Title: '',
                    Content: "",
                    UserName: "",
                    IsTop: "false"
                }
                var checkinp = function () {
                    if (!$scope.editNotice.Title) {
                        toaster.pop('warning', '', '请填写标题 ');
                        return
                    }
                    if (!$scope.editNotice.UserName) {
                        toaster.pop('warning', '', '请填写客服信息');
                        return
                    }
                    if (!$scope.editNotice.Content) {
                        toaster.pop('warning', '', '请填写内容');
                        return
                    }
                    // $scope.addNotice.Content = encodeURIComponent($scope.addNotice.Content);
                    return true
                }
                var initDate = function () {
                    $scope.Id = localStorage.getItem("NoticesId")
                    commonFactory.ajax("/api/Notices/GetNoticesById", { "": $scope.Id }, function (result) {
                        $scope.editNotice = result
                        if ($scope.editNotice.IsTop == true) {
                            $scope.editNotice.IsTop = "true"
                        } else {
                            $scope.editNotice.IsTop = "false"
                        }
                    }, function () {
                        toaster.pop('error', '', '后台错误');
                    }, "post");
                }
                initDate()
                $scope.editNotices = function () {
                    if (checkinp()) {
                        commonFactory.loading(true)
                        $scope.editNotice.Content = encodeURIComponent($scope.editNotice.Content);
                        commonFactory.ajax("/api/Notices/EditNotices", $scope.editNotice, function (result) {
                            commonFactory.loading(false)
                            if (result.Code == 1) {
                                toaster.pop('success', '', '编辑成功');
                                $modalInstance.close()
                            } else {
                                toaster.pop('warning', '', '编辑失败');
                            }
                        }, function () {
                            commonFactory.loading(false)
                            toaster.pop('error', '', '后台错误');
                        }, "post");
                    }
                }
                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: '',
            backdrop: false
        });
        modalInstance.result.then(function (selectedItem) {
            requestNoticeList()
        }, function () {

        });
    }
    var requestNoticeList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Notices/QueryNoticesList", $scope.QueryNotice, function (result) {
            $scope.graybtn = false;
            commonFactory.loading(false)
            if (result.Code == 1) {
                $scope.NoticeGroupList = result.List;
                $scope.NoticeGroupTotal = result.Total;
                $scope.page = Math.ceil(result.Total / $scope.QueryNotice.PageSize);
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requestNoticeList()
}]);

// 红包管理
app.controller('savered', ['$scope', 'commonFactory', 'toaster', '$timeout', function ($scope, commonFactory, toaster, $timeout) {
    $scope.allred = {
        type: '2',
        price: '',
        one: 500,
        three: 200,
        six: 100,
        startTime: new Date(),
        expirationTime: '',
        mobiles: ''
    }
    if ($scope.allred.startTime) {
        $scope.allred.startTime = commonFactory.DateFormat($scope.allred.startTime, 1)
    }
    var checkinp = function () {
        if (!$scope.allred.price) {
            toaster.pop('warning', '', '请填写金额');
            return
        }
        if (!$scope.allred.one) {
            toaster.pop('warning', '', '请填写一月标比例');
            return
        }
        if (!$scope.allred.three) {
            toaster.pop('warning', '', '请填写三月标比例');
            return
        }
        if (!$scope.allred.six) {
            toaster.pop('warning', '', '请填写六月标比例');
            return
        }
        var select = document.querySelector('#myinp').value;
        if (!select) {
            toaster.pop('warning', '', '请填写结束时间');
            return
        }
        var startTime = new Date($scope.allred.startTime).getTime();  
        var expirationTime =new Date($scope.allred.expirationTime).getTime();
        if(startTime>expirationTime){
            toaster.pop('warning', '', '结束日期必须大于等于开始日期');
            return
        }
        if (!$scope.allred.mobiles) {
            toaster.pop('warning', '', '请填写手机号');
            return
        }
        return true
    }
    $scope.show = true;
    $scope.butplus = function () {
        if (checkinp() && $scope.show) {
            $scope.show = false;
            $scope.allred.startTime = commonFactory.DateFormat($scope.allred.startTime);
            $scope.allred.expirationTime = commonFactory.DateFormat($scope.allred.expirationTime);
            commonFactory.loading(true)
            commonFactory.ajax("/api/RedPacket/InsertRedPacket", $scope.allred, function (result) {
                commonFactory.loading(false)
                $timeout(function() {
                    $scope.show = true;
                }, 500);
                if (result.Code == 1) {
                    toaster.pop('success', '', result.ResposeData);
                } else {
                    toaster.pop('warning', '', '未发放成功');
                }
            }, function () {
                commonFactory.loading(false)
                toaster.pop('error', '', '后台错误');
            }, "post");
        }
    }

}]);

//大于1000
app.controller('thousand', ['$scope', 'commonFactory', 'toaster', '$modal', function ($scope, commonFactory, toaster, $modal) {
    var today = new Date()
    $scope.QueryNotice = {
        PageIndex: 1,
        PageSize: 5,
        Time: today
    }
    $scope.QueryNotice.Time = commonFactory.DateFormat($scope.QueryNotice.Time, 1);
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.QueryNotice.PageIndex >= $scope.page) {//判断最大页码
                $scope.QueryNotice.PageIndex = $scope.page;
                return false;
            }
            $scope.QueryNotice.PageIndex++
            requestNoticeList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.QueryNotice.PageIndex <= 1) {//判断最小页码
            $scope.QueryNotice.PageIndex = 1;
            return false;
        }
        $scope.QueryNotice.PageIndex--;
        requestNoticeList()
    }
    $scope.QueryNotices = function () {
        $scope.graybtn = true;
        $scope.QueryNotice.PageIndex = 1;
        $scope.QueryNotice.Time = commonFactory.DateFormat($scope.QueryNotice.Time, 1);
        requestNoticeList();
    }


    var requestNoticeList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/Other/GetExtractUser", $scope.QueryNotice, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Code == 1) {
                $scope.GetExtractUser = result.userWithdrawNotesDto;
                $scope.NoticeGroupTotal = result.Total;
                $scope.page = Math.ceil(result.Total / $scope.QueryNotice.PageSize);
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requestNoticeList()

}]);

//还款管理
app.controller('repayproductinfofoinvest', ['$scope', 'commonFactory', 'toaster', '$modal', function ($scope, commonFactory, toaster, $modal) {
    var today = new Date()
    $scope.RepayProductInfo = {
        time: today
    }
    var RepayProductInfoFoInvest = function () {
        if ($scope.RepayProductInfo.time) {
            $scope.RepayProductInfo.time = commonFactory.DateFormat($scope.RepayProductInfo.time, 1)
        }
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.baseurlstatistic + "/Other/RepayProductInfoFoInvest", { Dt: $scope.RepayProductInfo.time }, function (result) {
            $scope.graybtn = false;
            commonFactory.loading(false)
            if (result.Code == 1) {
                $scope.RepayProductInfoFoInvest = result.RepayProductInfoFoInvestInfos
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    RepayProductInfoFoInvest()
    $scope.search = function () {
        $scope.graybtn = true;
        RepayProductInfoFoInvest()
    }

}]);
// 银行卡限额
app.controller('banklimit', ['$scope', '$rootScope', 'commonFactory', 'toaster', '$modal', '$timeout', function ($scope, $rootScope, commonFactory, toaster, $modal, $timeout) {
    // 添加
    $scope.addAd = function () {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', function ($scope, $modalInstance, toaster, commonFactory, $timeout) {
                $scope.Adbanklimit = true;
                $scope.adbank = true;//添加
                $scope.limit = {
                    BankName: '',
                    BankCode: '',
                    BankIcon: '',
                    SinglePrice: '',
                    DayPrice: '',
                    MonthPrice: ''
                }
                $scope.banklimit = {
                    SinglePrice: '',
                    DayPrice: '',
                    MonthPrice: ''
                }
                $scope.perice = {
                    SinglePrice: '10000',
                    DayPrice: '10000',
                    MonthPrice: '10000'
                }
                var bankprice = function () {
                    if (!$scope.limit.BankName) {
                        toaster.pop('warning', '', '请填写银行卡名称');
                        return
                    }
                    if (!$scope.limit.BankCode) {
                        toaster.pop('warning', '', '请填写银行卡编码');
                        return
                    }

                    if (!$scope.limit.BankIcon) {
                        toaster.pop('warning', '', '请上传银行卡logo');
                        return
                    }
                    if (!$scope.banklimit.SinglePrice) {
                        toaster.pop('warning', '', '请选择单笔限额');
                        return
                    }
                    if (!$scope.banklimit.DayPrice) {
                        toaster.pop('warning', '', '请选择单日限额');
                        return
                    }
                    $scope.limit.SinglePrice = $scope.banklimit.SinglePrice * $scope.perice.SinglePrice;
                    $scope.limit.DayPrice = $scope.banklimit.DayPrice * $scope.perice.DayPrice;
                    if ($scope.banklimit.MonthPrice && $scope.perice.MonthPrice) {
                        $scope.limit.MonthPrice = $scope.banklimit.MonthPrice * $scope.perice.MonthPrice;
                    } else {
                        $scope.limit.MonthPrice = ''
                    }
                    return true
                }
                var off = true
                $scope.addbanklimit = function () {
                    if (bankprice() && off) {
                        off = false
                        commonFactory.loading(true)
                        commonFactory.ajax("/api/bank/Add", $scope.limit, function (result) {
                            commonFactory.loading(false)
                            off = true
                            if (result.Code == 1) {
                                toaster.pop('success', '', '添加成功');
                                $modalInstance.close('cancel');
                            } else {
                                toaster.pop('error', '', result.ResposeData)
                            }
                        }, function () {
                            commonFactory.loading(false)
                        }, "post");
                    }
                }
                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'lg',
            backdrop: true
        });
        modalInstance.result.then(function (selectedItem) {
            requestAdList()
        }, function () {

        });
    }
    //修改
    $scope.editbanklimit = function (id) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'toaster', 'commonFactory', '$timeout', 'id', '$interval', function ($scope, $modalInstance, toaster, commonFactory, $timeout, id, $interval) {
                $scope.Adbanklimit = true;
                $scope.eidtbank = true;//修改
                $scope.limit = {
                    BankName: '',
                    BankCode: '',
                    BankIcon: '',
                    SinglePrice: '',
                    DayPrice: '',
                    MonthPrice: ''
                }
                $scope.banklimit = {
                    SinglePrice: '',
                    DayPrice: '',
                    MonthPrice: ''
                }
                $scope.perice = {
                    SinglePrice: '',
                    DayPrice: '',
                    MonthPrice: ''
                }
                var interval = $interval(function () {
                    if ($scope.limit.BankIcon) {
                        $interval.cancel(interval);
                        $scope.imgurlad = $scope.limit.BankIcon;//无法优化
                    }
                }, 100)
                var checkinp = function () {
                    if (!$scope.limit.BankName) {
                        toaster.pop('warning', '', '请填写银行卡名称');
                        return
                    }
                    if (!$scope.limit.BankCode) {
                        toaster.pop('warning', '', '请填写银行卡编码');
                        return
                    }

                    if (!$scope.limit.BankIcon) {
                        toaster.pop('warning', '', '请上传银行卡logo');
                        return
                    }
                    if (!$scope.banklimit.SinglePrice) {
                        toaster.pop('warning', '', '请选择单笔限额');
                        return
                    }
                    if (!$scope.banklimit.DayPrice) {
                        toaster.pop('warning', '', '请选择单日限额');
                        return
                    }
                    $scope.limit.SinglePrice = $scope.banklimit.SinglePrice * $scope.perice.SinglePrice;
                    $scope.limit.DayPrice = $scope.banklimit.DayPrice * $scope.perice.DayPrice;
                    if ($scope.banklimit.MonthPrice && $scope.perice.MonthPrice) {
                        $scope.limit.MonthPrice = $scope.banklimit.MonthPrice * $scope.perice.MonthPrice;
                    } else {
                        $scope.limit.MonthPrice = ''
                    }
                    return true
                }
                var initData = function () {//初始化数据
                    commonFactory.loading(true)
                    commonFactory.ajax("/api/bank/GetBankById", { "": id }, function (result) {
                        commonFactory.loading(false)
                        if (result.SinglePrice && result.SinglePrice % 1000 == 0 && result.SinglePrice > 10000) {
                            result.SinglePrice = result.SinglePrice / 10000;//数据除10000绑定数据
                            $scope.perice.SinglePrice = 10000;//出事化赋值单选
                        } else {
                            result.SinglePrice = result.SinglePrice / 1000;
                            $scope.perice.SinglePrice = 1000;
                        }
                        if (result.DayPrice && result.DayPrice % 1000 == 0 && result.DayPrice > 10000) {
                            result.DayPrice = result.DayPrice / 10000;
                            $scope.perice.DayPrice = 10000;
                        } else {
                            result.DayPrice = result.DayPrice / 1000;
                            $scope.perice.DayPrice = 1000;
                        }
                        if (result.MonthPrice) {
                            if (result.MonthPrice % 1000 == 0 && result.MonthPrice > 10000) {
                                result.MonthPrice = result.MonthPrice / 10000;
                                $scope.perice.MonthPrice = 10000;
                            } else {
                                result.MonthPrice = result.MonthPrice / 1000
                                $scope.perice.MonthPrice = 1000;
                            }
                        }
                        $scope.limit = {
                            BankName: result.BankName,
                            BankCode: result.BankCode,
                            BankIcon: result.BankIcon,
                            Id: id
                        }
                        $scope.banklimit = {
                            SinglePrice: result.SinglePrice,
                            DayPrice: result.DayPrice,
                            MonthPrice: result.MonthPrice
                        }

                    }, function () {
                        commonFactory.loading(false)
                        toaster.pop('error', '', '后台错误');
                    }, "post");
                }
                initData()
                var off = true
                $scope.editbanklimit = function () {
                    if (checkinp() && off) {
                        off = false
                        commonFactory.loading(true)
                        commonFactory.ajax("/api/bank/Update", $scope.limit, function (result) {
                            commonFactory.loading(false)
                            off = true
                            if (result.Code == 1) {
                                toaster.pop('success', '', '修改成功');
                                $modalInstance.close('cancel');
                            } else {
                                toaster.pop('error', '', result.ResposeData);
                            }
                        }, function () {
                            commonFactory.loading(false)
                            toaster.pop('error', '', '后台错误');
                        }, "post");
                    }
                }
                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: '',
            backdrop: true,
            resolve: {
                id: function () {
                    return id;
                }
            }
        });
        modalInstance.result.then(function (selectedItem) {
            requestAdList()
        }, function () {

        });
    }
    //删除
    $scope.deldata = function (id) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'items', 'toaster', 'commonFactory', function ($scope, $modalInstance, items, toaster, commonFactory) {
                $scope.items = items;
                $scope.dellimit = items;
                $scope.ok = function () {
                    //删除
                    commonFactory.loading(true)
                    commonFactory.ajax("/api/bank/Delete", { '': items }, function (result) {
                        commonFactory.loading(false)
                        if (result.Code == 1) {
                            toaster.pop('success', '', '删除成功');
                            $modalInstance.close();
                        } else if (result.Code == 3) {
                            toaster.pop('warning', '', '不能删除，已有用户绑定了该银行卡');
                            $modalInstance.close();
                        } else {
                            toaster.pop('error', '', '删除失败');
                            $modalInstance.close();
                        }
                        requestAdList()
                    }, function () {
                        commonFactory.loading(false)
                    }, "post");
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false,
            resolve: {
                items: function () {
                    return id;
                }
            }
        });
        modalInstance.result.then(function (selectedItem) {

            requestAdList();

        }, function () {

        });
    }
    $scope.searchbankcard = {
        Index: 1,
        Size: 16,
        BankName: '',
        BankCode: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.searchbankcard.Index >= $scope.page) {//判断最大页码
                $scope.searchbankcard.Index = $scope.page;
                return false;
            }
            $scope.searchbankcard.Index++
            requestAdList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.searchbankcard.Index <= 1) {//判断最小页码
            $scope.searchbankcard.Index = 1;
            return false;
        }
        $scope.searchbankcard.Index--;
        requestAdList()
    }
    $scope.inpvalue = {
        num: '1'
    }
    // 查询
    $scope.querybank = function () {
        $scope.graybtn = true;
        if (!$scope.bindname) {
            requestAdList();
            return
        }
        if ($scope.inpvalue.num == 1) {
            $scope.searchbankcard.BankName = $scope.bindname
            $scope.searchbankcard.BankCode = ''
        } else {
            $scope.searchbankcard.BankCode = $scope.bindname;
            $scope.searchbankcard.BankName = ''
        }
        $scope.searchbankcard.Index = 1;
        requestAdList();
    }
    $scope.delcache = function () {
        commonFactory.ajax("/api/Bank/RemoveCache", $scope.searchbankcard, function (result) {

        }, function () { }, 'post')
    }
    var requestAdList = function () {
        commonFactory.loading(true)
        commonFactory.ajax("/api/bank/GetBankList", $scope.searchbankcard, function (result) {
            commonFactory.loading(false)
            $scope.graybtn = false;
            if (result.Data != null) {
                $scope.GetBankList = result.Data;
                $scope.QueryListTotal = result.Count;
                $scope.page = Math.ceil(result.Count / $scope.searchbankcard.Size);
                var sortindex = function (id, type, targetId) {
                    commonFactory.ajax("/api/bank/Sort", { Id: id, Type: type, targetid: targetId }, function (result) {
                        if (result.Code == 1) {
                        } else {
                            toaster.pop('error', '', '修改失败');
                        }
                    }, function () {
                        toaster.pop('error', '', '后台错误');
                    }, "post");
                }

                $scope.getup = function (id, index) {
                    if (index == 0) {
                        return;
                    }
                    var obj_temp = $scope.GetBankList[index - 1];
                    $scope.GetBankList.splice(index - 1, 1, $scope.GetBankList[index])
                    $scope.GetBankList.splice(index, 1, obj_temp)
                    sortindex(id, 0, obj_temp.Id)
                }
                $scope.getdown = function (id, index) {
                    if (index == result.Data.length - 1) {
                        return;
                    }
                    var obj_temp = $scope.GetBankList[index + 1]
                    $scope.GetBankList.splice(index + 1, 1, $scope.GetBankList[index])
                    $scope.GetBankList.splice(index, 1, obj_temp)
                    sortindex(id, 1, obj_temp.Id)
                }
            } else {
                commonFactory.loading(false)
                $scope.graybtn = false;
                toaster.pop('error', '', '失败');
            }
        }, function () {

        }, "post");
    }
    requestAdList()

}]);